<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="../../template/tagedu.xhtml">

    <ui:define name="title">
        <title><h:outputText value="TAG - Consulta Ator"/></title>
        <f:metadata>
            <f:viewParam name="personage" value="#{humanSearch.personageID}"/>            
        </f:metadata>
    </ui:define>

    <ui:define name="content">
        <f:event type="preRenderComponent" listener="#{humanSearch.init()}"/>
        <h:outputText styleClass="personageName" value="Consulta de #{humanSearch.getPersonageName()}"/>
        <h:form id="humanSearchForm" styleClass="searchForm">
            <p:messages id="message"/>
            <br/>
            <p:dataTable value="#{humanSearch.actors}" var="actor" paginator="true" rows="10"
                         id="humanSearchTable" lazy="true"
                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                         rowsPerPageTemplate="10,25,50,100" emptyMessage="Não há atores cadastrados" filteredValue="#{humanSearch.filteredActors}">
                <p:column>
                    <p:rowToggler/>
                </p:column>
                <p:column filterStyle="width: 200px" headerText="Nome"
                          filterBy="name"  
                          filterMatchMode="contains">
                    <h:outputLink value="../edit/humanEdit.xhtml">
                        <f:param value="#{actor.person.id}" name="human"/>
                        <h:outputText value="#{actor.person.name}"/>
                    </h:outputLink>
                </p:column>
                <p:column>
                    <f:facet name="header">
                        <h:outputText value="Unidade"/>
                    </f:facet>
                    <h:outputText value="#{actor.unity.name}"/>
                </p:column>
                <p:column id="activationColumn">
                    <f:facet name="header">
                        <h:outputText value="Ativação"/>
                    </f:facet>
                    <h:outputText value="#{actor.activated.time}">
                        <f:convertDateTime pattern="dd/MM/yyyy"/>
                    </h:outputText>
                </p:column>
                <p:column id="deactivationColumn">
                    <f:facet name="header">
                        <h:outputText value="Desativação"/>
                    </f:facet>
                    <h:outputText value="#{actor.deactivated.time}">
                        <f:convertDateTime pattern="dd/MM/yyyy"/>
                    </h:outputText>
                </p:column>
                <p:rowExpansion>
                    <h:panelGrid columns="2" cellpadding="4">
                        <h:outputLabel value="Nascimento: " for="birthday"/>
                        <h:outputText value="#{actor.person.birthday.time}" id="birthday">
                            <f:convertDateTime pattern="dd/MM/yyyy"/>
                        </h:outputText>
                        <h:outputLabel value="Endereço: " for="address"/>
                        <h:outputText value="#{actor.person.address.street.name}, #{actor.person.address.number}.
                                      #{actor.person.address.complement}. #{actor.person.address.zipcode.city.name}/#{actor.person.address.zipcode.city.state.name}" id="address"/>
                        <ui:repeat value="#{humanSearch.personAdditionalInfo(actor.person.id)}" var="addInfo">
                            <h:outputLabel value="#{addInfo.additionalInfoType.acronym}: "/>
                            <h:outputText value="#{addInfo.value}"/>
                        </ui:repeat>
                    </h:panelGrid>
                </p:rowExpansion>
                <p:column>
                    <f:facet name="header">
                        <h:outputText value="Edição"/>
                    </f:facet>
                    <p:commandButton icon="ui-icon-search" ajax="true" update=":editActorForm"
                                     oncomplete="editActor.show();"
                                     action="#{humanSearch.preEdit()}">
                        <f:setPropertyActionListener value="#{actor}" target="#{humanSearch.actor}"/>
                    </p:commandButton>
                </p:column>
            </p:dataTable>
        </h:form>
    </ui:define>

    <ui:define name="modals">
        <p:dialog modal="true" header="Editar ator" widgetVar="editActor" resizable="false"
                  width="500" height="200">
            <h:form id="editActorForm">
                <p:messages/>
                <h:panelGrid columns="2">
                    <h:outputLabel value="Nome: " for="name"/>
                    <h:outputText id="name" 
                                  value="#{humanSearch.actor.person.name}"/>

                    <h:outputLabel for="activation" value="Ativação: "/>
                    <p:inputMask id="activation" mask="99/99/9999" 
                                 value="#{humanSearch.actor.activated.time}"
                                 required="true" 
                                 requiredMessage="Ativação é obrigatório">
                        <f:convertDateTime pattern="dd/MM/yyyy"/>
                    </p:inputMask>
                    <h:outputLabel for="deactivation" value="Desativação: "/>
                    <p:inputMask id="deactivation" mask="99/99/9999" value="#{humanSearch.deactivation}">
                        <f:convertDateTime pattern="dd/MM/yyyy"/>
                    </p:inputMask>
                    <p:commandButton value="Editar" process="@form"
                                     ajax="true" action="#{humanSearch.edit()}"
                                     update="@form :humanSearchForm"
                                     oncomplete="handleSubmitRequest(xhr, status, args)"/>

                </h:panelGrid>
            </h:form>
        </p:dialog>

        <p:dialog modal="true" widgetVar="statusDialog" 
                  draggable="false" closable="false">
            <p:graphicImage value="../../resources/images/ajax/ajaxloader.gif"/>
        </p:dialog>
        
        <script type="text/javascript">  
            function handleSubmitRequest(xhr, status, args) {  
                if (!args.validationFailed) {
                    editActor.hide();
                    confirmExclusion.hide();
                }   
            }
        </script>
    </ui:define>
</ui:composition>